﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace WeixinBusiness.Model
{
    public class ResultMsg
    {
        //"errcode":0,"errmsg":"ok"

        private int _errcode = 0;

        [JsonProperty("errcode")]
        public virtual int ErrorCode
        {
            get { return _errcode; }
            set { _errcode = value; }
        }

        private string _errmsg = string.Empty;

        [JsonProperty("errmsg")]
        public virtual string ErrorMsg
        {
            get { return _errmsg; }
            set { _errmsg = value; }
        }

        private long _msg_id = 0;
        /// <summary>
        /// 群发消息ID
        /// </summary>
        [JsonProperty("msg_id")]
        public long Msg_Id
        {
            get { return _msg_id; }
            set { _msg_id = value; }
        }

        private long _msgid = 0;
        /// <summary>
        /// 模板消息ID
        /// </summary>
        [JsonProperty("msgid")]
        public long MsgId
        {
            get { return _msgid; }
            set { _msgid = value; }
        }

        private string _msg = "";
        public string Message
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_msg))
                {
                    switch (ErrorCode)
                    {
                        case -1:
                            _msg = "系统繁忙";
                            break;
                        case 0:
                            _msg = "请求成功";
                            break;
                        case 40001:
                            _msg = "获取access_token时AppSecret错误，或者access_token无效";
                            break;
                        case 40002:
                            _msg = "不合法的凭证类型";
                            break;
                        case 40003:
                            _msg = "不合法的OpenID";
                            break;
                        case 40004:
                            _msg = "不合法的媒体文件类型";
                            break;
                        case 40005:
                            _msg = "不合法的文件类型";
                            break;
                        case 40006:
                            _msg = "不合法的文件大小";
                            break;
                        case 40007:
                            _msg = "不合法的媒体文件id";
                            break;
                        case 40008:
                            _msg = "不合法的消息类型";
                            break;
                        case 40009:
                            _msg = "不合法的图片文件大小";
                            break;
                        case 40010:
                            _msg = "不合法的语音文件大小";
                            break;
                        case 40011:
                            _msg = "不合法的视频文件大小";
                            break;
                        case 40012:
                            _msg = "不合法的缩略图文件大小";
                            break;
                        case 40013:
                            _msg = "不合法的APPID";
                            break;
                        case 40014:
                            _msg = "不合法的access_token";
                            break;
                        case 40015:
                            _msg = "不合法的菜单类型";
                            break;
                        case 40016:
                            _msg = "不合法的按钮个数";
                            break;
                        case 40017:
                            _msg = "不合法的按钮个数";
                            break;
                        case 40018:
                            _msg = "不合法的按钮名字长度";
                            break;
                        case 40019:
                            _msg = "不合法的按钮KEY长度";
                            break;
                        case 40020:
                            _msg = "不合法的按钮URL长度";
                            break;
                        case 40021:
                            _msg = "不合法的菜单版本号";
                            break;
                        case 40022:
                            _msg = "不合法的子菜单级数";
                            break;
                        case 40023:
                            _msg = "不合法的子菜单按钮个数";
                            break;
                        case 40024:
                            _msg = "不合法的子菜单按钮类型";
                            break;
                        case 40025:
                            _msg = "不合法的子菜单按钮名字长度";
                            break;
                        case 40026:
                            _msg = "不合法的子菜单按钮KEY长度";
                            break;
                        case 40027:
                            _msg = "不合法的子菜单按钮URL长度";
                            break;
                        case 40028:
                            _msg = "不合法的自定义菜单使用用户";
                            break;
                        case 40029:
                            _msg = "不合法的oauth_code";
                            break;
                        case 40030:
                            _msg = "不合法的refresh_token";
                            break;
                        case 40031:
                            _msg = "不合法的openid列表";
                            break;
                        case 40032:
                            _msg = "不合法的openid列表长度";
                            break;
                        case 40033:
                            _msg = "不合法的请求字符，不能包含\\uxxxx格式的字符";
                            break;
                        case 40035:
                            _msg = "不合法的参数";
                            break;
                        case 40038:
                            _msg = "合法的请求格式";
                            break;
                        case 40039:
                            _msg = "不合法的URL长度";
                            break;
                        case 40050:
                            _msg = "不合法的分组id";
                            break;
                        case 40051:
                            _msg = "分组名字不合法";
                            break;
                        case 41001:
                            _msg = "缺少access_token参数";
                            break;
                        case 41002:
                            _msg = "缺少appid参数";
                            break;
                        case 41003:
                            _msg = ":缺少refresh_token参数";
                            break;
                        case 41004:
                            _msg = "缺少secret参数";
                            break;
                        case 41005:
                            _msg = "缺少多媒体文件数据";
                            break;
                        case 41006:
                            _msg = "缺少media_id参数";
                            break;
                        case 41007:
                            _msg = "缺少子菜单数据";
                            break;
                        case 41008:
                            _msg = "缺少oauth code";
                            break;
                        case 41009:
                            _msg = "缺少openid";
                            break;
                        case 42001:
                            _msg = "access_token超时";
                            break;
                        case 42002:
                            _msg = "refresh_token超时";
                            break;
                        case 42003:
                            _msg = "oauth_code超时";
                            break;
                        case 43001:
                            _msg = "需要GET请求";
                            break;
                        case 43002:
                            _msg = "需要POST请求";
                            break;
                        case 43003:
                            _msg = "需要HTTPS请求";
                            break;
                        case 43004:
                            _msg = "需要接收者关注";
                            break;
                        case 43005:
                            _msg = "需要好友关系";
                            break;
                        case 44001:
                            _msg = "多媒体文件为空";
                            break;
                        case 44002:
                            _msg = "POST的数据包为空";
                            break;
                        case 44003:
                            _msg = "图文消息内容为空";
                            break;
                        case 44004:
                            _msg = "文本消息内容为空";
                            break;
                        case 45001:
                            _msg = "多媒体文件大小超过限制";
                            break;
                        case 45002:
                            _msg = "消息内容超过限制";
                            break;
                        case 45003:
                            _msg = "标题字段超过限制";
                            break;
                        case 45004:
                            _msg = "描述字段超过限制";
                            break;
                        case 45005:
                            _msg = "链接字段超过限制";
                            break;
                        case 45006:
                            _msg = "图片链接字段超过限制";
                            break;
                        case 45007:
                            _msg = "语音播放时间超过限制";
                            break;
                        case 45008:
                            _msg = "图文消息超过限制";
                            break;
                        case 45009:
                            _msg = "接口调用超过限制";
                            break;
                        case 45010:
                            _msg = "创建菜单个数超过限制";
                            break;
                        case 45015:
                            _msg = "回复时间超过限制";
                            break;
                        case 45016:
                            _msg = "系统分组，不允许修改";
                            break;
                        case 45017:
                            _msg = "分组名字过长";
                            break;
                        case 45018:
                            _msg = "分组数量超过上限";
                            break;
                        case 46001:
                            _msg = "不存在媒体数据";
                            break;
                        case 46002:
                            _msg = "不存在的菜单版本";
                            break;
                        case 46003:
                            _msg = "不存在的菜单数据";
                            break;
                        case 46004:
                            _msg = "不存在的用户";
                            break;
                        case 47001:
                            _msg = "解析JSON/XML内容错误";
                            break;
                        case 48001:
                            _msg = "api功能未授权";
                            break;
                        case 50001:
                            _msg = "用户未授权该api ";
                            break;
                        case 61451:
                            _msg = "参数错误(invalid parameter)";
                            break;
                        case 61452:
                            _msg = "无效客服账号(invalid kf_account)";
                            break;
                        case 61453:
                            _msg = "客服帐号已存在(kf_account exsited)";
                            break;
                        case 61454:
                            _msg = "客服帐号名长度超过限制(仅允许10个英文字符，不包括@及@后的公众号的微信号)(invalid kf_acount length)";
                            break;
                        case 61455:
                            _msg = "客服帐号名包含非法字符(仅允许英文+数字)(illegal character in kf_account)";
                            break;
                        case 61456:
                            _msg = "客服帐号个数超过限制(10个客服账号)(kf_account count exceeded)";
                            break;
                        case 61457:
                            _msg = "无效头像文件类型(invalid file type)";
                            break;
                        case 61450:
                            _msg = "系统错误(system error)";
                            break;
                        case 61458:
                            _msg = "客户正在被其他客服接待";
                            break;
                        case 61459:
                            _msg = "客服不在线(kf offline)";
                            break;
                        case 61500:
                            _msg = "日期格式错误";
                            break;
                        case 61501:
                            _msg = "日期范围错误";
                            break;
                        case 9001001:
                            _msg = "POST数据参数不合法";
                            break;
                        case 9001002:
                            _msg = "远端服务不可用";
                            break;
                        case 9001003:
                            _msg = "Ticket不合法";
                            break;
                        case 9001004:
                            _msg = "获取摇周边用户信息失败";
                            break;
                        case 9001005:
                            _msg = "获取商户信息失败";
                            break;
                        case 9001006:
                            _msg = "获取OpenID失败";
                            break;
                        case 9001007:
                            _msg = "上传文件缺失";
                            break;
                        case 9001008:
                            _msg = "上传素材的文件类型不合法";
                            break;
                        case 9001009:
                            _msg = "上传素材的文件尺寸不合法";
                            break;
                        case 9001010:
                            _msg = "上传失败";
                            break;
                        case 9001020:
                            _msg = "帐号不合法";
                            break;
                        case 9001021:
                            _msg = "已有设备激活率低于50%，不能新增设备";
                            break;
                        case 9001022:
                            _msg = "设备申请数不合法，必须为大于0的数字";
                            break;
                        case 9001023:
                            _msg = "已存在审核中的设备ID申请";
                            break;
                        case 9001024:
                            _msg = "一次查询设备ID数量不能超过50";
                            break;
                        case 9001025:
                            _msg = "设备ID不合法";
                            break;
                        case 9001026:
                            _msg = "页面ID不合法";
                            break;
                        case 9001027:
                            _msg = "页面参数不合法";
                            break;
                        case 9001028:
                            _msg = "一次删除页面ID数量不能超过10";
                            break;
                        case 9001029:
                            _msg = "页面已应用在设备中，请先解除应用关系再删除";
                            break;
                        case 9001030:
                            _msg = "一次查询页面ID数量不能超过50";
                            break;
                        case 9001031:
                            _msg = "时间区间不合法";
                            break;
                        case 9001032:
                            _msg = "保存设备与页面的绑定关系参数错误";
                            break;
                        case 9001033:
                            _msg = "门店ID不合法";
                            break;
                        case 9001034:
                            _msg = "设备备注信息过长";
                            break;
                        case 9001035:
                            _msg = "设备申请参数不合法";
                            break;
                        case 9001036:
                            _msg = "查询起始值begin不合法 ";
                            break;
                        default:
                            _msg = ErrorMsg;
                            break;
                    }
                }
                return _msg;
            }
            set
            {
                _msg = value;
            }
        }

        /// <summary>
        /// 格式化输出，便于输出调试信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var item in this.GetType().GetProperties())
            {
                if (item.Name.Equals("Item"))
                {
                    continue;
                }
                sb.AppendFormat("{0}={1},", item.Name, item.GetValue(this, null));
            }
            return sb.ToString().TrimEnd(',');
        }
    }
}
